package API.Class.Math.GetFactorPro;

import API.Exception.ZeroNumberException;
import API.Exception.OnlyOneNumberException;

import java.util.Scanner;

/**
 * 示例代码：可供程序员学习如何调用方法的示例
 */
public class ExampleClass {
    public String Example() throws ZeroNumberException, OnlyOneNumberException {
        //创建扫描器
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要多少个因数");
        //在控制台中获取需要多少因数
        int howMany = sc.nextInt();
        StringBuffer str = new StringBuffer();
        //从控制台中获取所有因数
        for (int i = 1; i < howMany + 1; i++) {
            System.out.println("请输入第" + i + "个正整数：");
            String d = String.valueOf(sc.nextLong());
            str = str.append(d);
            str = str.append("|");
        }
        //进行整理StringBuffer类
        int len = str.length() - 1;
        str = str.deleteCharAt(len);
        //将StringBuffer对象换成long数组
        long[] l = this.Run(howMany, str);
        StringBuffer sb = new StringBuffer();
        //遍历数组
        for (long i : l) {
            sb.append(i + " ");
        }
        sb = sb.deleteCharAt(sb.length() - 1);
        String sr = sb.toString();
        return sb.toString();
    }

    public long[] Run(int howMany, StringBuffer str) throws ZeroNumberException, OnlyOneNumberException {
        //创建对象实例化
        TwoThread tw = new TwoThread(howMany, str);
        //运行主程序，并返回结果
        return tw.Run();
    }

}
